package utils;


/**
 * Created by bpb on 2019/10/22.
 * 说明：
 */
public class ClickHelper {

    private long currentTime;
    private int timeOut;
    private volatile boolean lock = false;

    public ClickHelper(int timeOut){
        this.timeOut = timeOut;
    }

    public boolean canClick(){
        if(lock){
            currentTime = System.currentTimeMillis();
            //直接返回 false
            return false;
        }

        long time = System.currentTimeMillis();
        if((time - currentTime) >= timeOut){
            currentTime = time;
            return true;
        }
        return false;
    }

    public void setClickLock(boolean lock){
        this.lock = lock;
    }

    public void setDelayProcess(){
        currentTime = System.currentTimeMillis();
        currentTime += timeOut;
    }
}
